package com.infovane.service.impl;

import java.util.List;

import com.infovane.dao.BaseDao;
import com.infovane.dao.UserDao;
import com.infovane.model.TUser;
import com.infovane.service.UserService;

public class UserServiceImpl implements UserService{
	
	private BaseDao baseDao;
	
	
	
	public BaseDao getBaseDao() {
		return baseDao;
	}



	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	
	private UserDao userDao;
	
	



	public UserDao getUserDao() {
		return userDao;
	}



	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}



	/**
	 * 根据用户名和密码获取用户对象
	 * @param username,password
	 * @return TUser
	 * */
	public TUser getUser(String username, String password) {
		List<TUser> userList=null;
		String hql="from TUser as u where u.userName=:userName and u.userPass=:userPass";
		userList=this.userDao.Load(hql, username, password);
		if(userList!=null&&userList.size()>0){
			return userList.get(0);
		}
		return null;
	}


	/**
	 * 根据用户名获取用户对象
	 * @param username
	 * @return TUser
	 * */
	public TUser getUser(String username) {
		List<TUser> userList=null;
		String hql="from TUser as u where u.userName=:userName";
		userList=this.userDao.load(hql, username);
		if(userList!=null&&userList.size()>0){
			return userList.get(0);
		}
		return null;
	}


	/**
	 * 
	 * 保存一个用户对象
	 * @param Objcet
	 * @return boolean
	 * */
	public boolean add(Object object) {
		
		return this.baseDao.save(object);
	}


	/**
	 * 根据用户ID获取用户对象
	 * @param modelClass, userId
	 * @return TUser
	 * */
	public TUser getUser(Class modelClass,Long userId) {
		
		return (TUser) this.baseDao.load(modelClass, userId);
	}


	/**
	 * 更新用户资料
	 * @param Object
	 * @return boolean
	 * */
	public boolean update(Object object) {
		
		return this.baseDao.update(object);
	}

}
